import {Command} from '../constant';
import Taro from '@tarojs/taro';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';
import api from 'api';
export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },
    async getMemberEquityNum() {
      const result = await api.MemberController.getMemberEquityNum();
      if (result) {
        dispatch({
          type: Command.init,
          payload: {
            main: {
              lanjingLength: result.blueLevelRightsVOList.length || '0',
              chijingLength: result.redLevelRightsVOList.length || '0',
            },
          },
        });
      }
    },
    async page() {
      const {
        main: {selectId},
      } = getData();
      this.getMemberEquityNum();
      const result = await api.BenefitsPageController.getBenefits({rightsType: selectId});
      action.commonChange('main.lanjingList', result.blueLevelRightsVOList || []);
      action.commonChange('main.chijingList', result.redLevelRightsVOList || []);
    },
    /**
     * 初始化
     */
    async query() {},
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageABenefitsPageMain'),
  };
}

//create by moon https://github.com/creasy2010/moon
